-- liquibase formatted sql

-- changeset n.parkhomenko:V1695412112_create_table_blogs
CREATE TABLE blogs
(
    id INT NOT NULL GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    name VARCHAR(50) NOT NULL,
    description TEXT NOT NULL,
    user_id INT NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMP DEFAULT NULL,
    CONSTRAINT fk_blog_user FOREIGN KEY (user_id) REFERENCES users (id)
        ON DELETE CASCADE
        ON UPDATE CASCADE
);

CREATE TABLE blog_posts
(
    id INT NOT NULL GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    blog_id INT,
    content TEXT NOT NULL,
    created_at TIMESTAMP NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMP DEFAULT NULL,
    CONSTRAINT fk_blog_post_post FOREIGN KEY (blog_id) REFERENCES blogs (id)
        ON DELETE CASCADE
        ON UPDATE CASCADE
);